package net.starwifi.duobao.web.db;

import net.starwifi.duobao.entity.DBCode;
import net.starwifi.duobao.entity.DBTimes;
import net.starwifi.duobao.mvc.*;
import net.starwifi.duobao.service.DBCodeService;
import net.starwifi.duobao.service.DBTimesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2015/12/3.
 */
@Controller("apiDBTimesRecordController")
@RequestMapping("/db")
public class DBTimesRecordController extends BaseController {


    @Autowired
    DBTimesService dbTimesService;

    @Autowired
    DBCodeService dbCodeService;

    /**
     * 往期揭晓
     */
    @RequestMapping(value = "/dbTimes-record", method = RequestMethod.GET)
    public String dbTimesRecord(Model model) {
        List<Order> orderBy=new ArrayList<Order>();
        orderBy.add(net.starwifi.duobao.mvc.Order.desc("endDate"));
        List<DBTimes> dbTimesList=dbTimesService.getListData(0,10,"o.isLottery=?1",new Object[]{Boolean.TRUE},orderBy);
        for(DBTimes data : dbTimesList){
            orderBy=new ArrayList<Order>();
            orderBy.add(net.starwifi.duobao.mvc.Order.desc("id"));
            List<DBCode>  list = dbCodeService.getListData("o.timesNo=?1 and o.memberId=?2", new Object[]{data.getTimesNo(),data.getMemberId()},orderBy);
            data.setLotteryCode(list);
        }
        model.addAttribute("dbTimesList", dbTimesList);
        return "/db/dbTimes-record";
    }

    @RequestMapping(value = "/dbTimes-record-content", method = RequestMethod.GET)
    public String dbTimesRecordContent(Model model,int pageNum) {
        PageView pageView=new PageView(pageNum,10);
        pageView.addOrder(net.starwifi.duobao.mvc.Order.desc("endDate"));
        pageView.addFilter(Filter.eq("isLottery",Boolean.TRUE));
        Page<DBTimes> page=dbTimesService.getScrollData(pageView);
        model.addAttribute("dbTimesList",page.getContent());
        return "/db/dbTimes-record-content";
    }


}
